<template>
  <el-radio-group v-if="current_args.style == 'button'" v-model="current_field" size="medium" :disabled="disabledValue">
    <el-radio-button v-for="option in radioOptions" :key="option.value" :label="option.value">{{ option.title }}</el-radio-button>
  </el-radio-group>
  <el-radio-group v-else-if="current_args.style == 'border'" v-model="current_field" size="medium" :disabled="disabledValue">
    <el-radio v-for="option in radioOptions" :key="option.value" :label="option.value" border>{{ option.title }}</el-radio>
  </el-radio-group>
  <el-radio-group v-else-if="current_args.style == 'default'" v-model="current_field" size="medium" :disabled="disabledValue">
    <el-radio v-for="option in radioOptions" :key="option.value" :label="option.value">{{ option.title }}</el-radio>
  </el-radio-group>
  <el-radio-group v-else v-model="current_field" size="medium" :disabled="disabledValue">
    <el-radio v-for="option in radioOptions" :key="option.value" :label="option.value">{{ option.title }}</el-radio>
  </el-radio-group>
</template>
<script>
export default {
  props: {
    value: {
      type: String,
      default: ''
    },
    args: {
      type: Object,
      required: true,
      default: _ => {
        return {};
      }
    },
    options: {
      type: Array,
      default: _ => {
        return [];
      }
    }
  },
  data() {
    return {
      current_field: this.value,
      current_args: this.args
    };
  },
  computed: {
    disabledValue() {
      if (this.current_args.disabled == '1') {
        return true;
      }

      return null;
    },
    radioOptions() {
      if (this.options.length > 0) {
        return this.options;
      }
      return [];
    }
  },
  watch: {
    current_field(value) {
      this.$emit('update:value', value);
    },
    value: {
      handler(now, old) {
        this.current_field = now;
      }
    }
  }
};
</script>
